package co.yixiang.modules.supplier.rest;

import co.yixiang.aop.log.Log;
import co.yixiang.modules.supplier.domain.SupplierGoodsSkuLog;
import co.yixiang.modules.supplier.service.SupplierGoodsSkuLogService;
import co.yixiang.modules.supplier.service.dto.SupplierGoodsSkuLogQueryCriteria;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

/**
* @author Walert
* @date 2021-03-27
*/
@Api(tags = "商品修改日志管理")
@RestController
@RequestMapping("/api/supplierGoodsSkuLog")
public class SupplierGoodsSkuLogController {

    private final SupplierGoodsSkuLogService supplierGoodsSkuLogService;

    public SupplierGoodsSkuLogController(SupplierGoodsSkuLogService supplierGoodsSkuLogService) {
        this.supplierGoodsSkuLogService = supplierGoodsSkuLogService;
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('supplierGoodsSkuLog:list')")
    public void download(HttpServletResponse response, SupplierGoodsSkuLogQueryCriteria criteria) throws IOException {
        supplierGoodsSkuLogService.download(supplierGoodsSkuLogService.queryAll(criteria), response);
    }

    @GetMapping
    @Log("查询商品修改日志")
    @ApiOperation("查询商品修改日志")
    @PreAuthorize("@el.check('supplierGoodsSkuLog:list')")
    public ResponseEntity<Object> getSupplierGoodsSkuLogs(SupplierGoodsSkuLogQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(supplierGoodsSkuLogService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @Log("新增商品修改日志")
    @ApiOperation("新增商品修改日志")
    @PreAuthorize("@el.check('supplierGoodsSkuLog:add')")
    public ResponseEntity<Object> create(@Validated @RequestBody SupplierGoodsSkuLog resources){
        return new ResponseEntity<>(supplierGoodsSkuLogService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @Log("修改商品修改日志")
    @ApiOperation("修改商品修改日志")
    @PreAuthorize("@el.check('supplierGoodsSkuLog:edit')")
    public ResponseEntity<Object> update(@Validated @RequestBody SupplierGoodsSkuLog resources){
        supplierGoodsSkuLogService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除商品修改日志")
    @ApiOperation("删除商品修改日志")
    @PreAuthorize("@el.check('supplierGoodsSkuLog:del')")
    @DeleteMapping
    public ResponseEntity<Object> deleteAll(@RequestBody Long[] ids) {
        supplierGoodsSkuLogService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
